package com.xxwy.lifecycle.resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.Resource;


/**
 * 外部配置.
 *
 * @author xxwy
 * @date 2021/7/13 0013
 */
@Configuration
@PropertySource(value = "META-INF/default.properties", encoding = "UTF-8")
public class ExternalConfigurationDependencySourceDemo {

    @Value("${application.version:0.0.1}")
    private String version;

    @Value("${user.age}")
    private Resource resource;

    /**
     * 有内至参数的优先级的问题
     */
    @Value("${user.nam}")
    private Resource name;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(ExternalConfigurationDependencySourceDemo.class);
        applicationContext.refresh();

        ExternalConfigurationDependencySourceDemo bean = applicationContext.getBean(ExternalConfigurationDependencySourceDemo.class);
        System.out.println(bean.version);
        System.out.println(bean.resource);
        System.out.println(bean.name);

        applicationContext.close();
    }
}
